package com.jiangyg.mall.member.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.member.dto.MemberStatisticsInfoDTO;
import com.jiangyg.mall.member.service.MemberStatisticsInfoService;
import com.jiangyg.mall.member.vo.MemberStatisticsInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：会员统计信息控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-30 07:33:08
 */
@RestController
@RequestMapping("/member/memberStatisticsInfo")
public class MemberStatisticsInfoController {

    /**
     * 会员统计信息接口
     */
    private final MemberStatisticsInfoService memberStatisticsInfoService;

    @Autowired
    public MemberStatisticsInfoController(MemberStatisticsInfoService memberStatisticsInfoService) {
        this.memberStatisticsInfoService = memberStatisticsInfoService;
    }

    /**
     * 功能描述：会员统计信息分页查询
     *
     * @param request    请求
     * @param pagination 分页参数
     * @return 返回分页会员统计信息
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<MemberStatisticsInfoVO>> select(HttpServletRequest request, @RequestBody Pagination<MemberStatisticsInfoVO> pagination) throws Exception {
        return Result.ok(memberStatisticsInfoService.selectPagination(pagination));
    }

    /**
     * 功能描述：保存或者修改会员统计信息
     *
     * @param request 请求
     * @param dto     会员统计信息
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated MemberStatisticsInfoDTO dto) throws Exception {
        return Result.saveOrUpdate(memberStatisticsInfoService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取会员统计信息
     *
     * @param request 请求
     * @param memberStatisticsInfoId  会员统计信息ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<MemberStatisticsInfoVO> info(HttpServletRequest request, @RequestParam(name = "memberStatisticsInfoId") Long memberStatisticsInfoId) throws Exception {
        return Result.ok(memberStatisticsInfoService.selectById(memberStatisticsInfoId));
    }

    /**
     * 功能描述：删除会员统计信息
     *
     * @param request 请求
     * @param memberStatisticsInfoIds 批量删除的会员统计信息ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestParam(name = "memberStatisticsInfoIds") List<Long> memberStatisticsInfoIds) {
        return Result.delete(memberStatisticsInfoService.delete(memberStatisticsInfoIds));
    }

}
